<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script>
			window.onload=function(){
				var num=0;
				var h1=document.getElementById("oH");
				var btn=document.getElementById("btn");
				//h1的内容从0开始每隔2秒增加1
				var timer=setInterval(function(){
					h1.innerHTML=num++;
				},2000);
				btn.onclick=function(){
					//点击按钮停止定时调用
					clearInterval(timer);
				}
			}
		</script>
	</head>
	<body>
		<h1 id="oH"></h1>
		<button id="btn">停止</button>
	</body>
</html>
